<?php
/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2014 All Rights Reserved.
 */



include('../AlipayMobilePublicMultiMediaClient.php');


header("Content-type: text/html; charset=gbk");

/**
 *
 * @author wangYuanWai
 * @version $Id: Test.hp, v 0.1 Aug 6, 2014 4:20:17 PM yikai.hu Exp $
 */
class TestImage{


	public $partner_public_key  = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAo1DVNK01WQpv2Lj3ckL+QwSU2B1xivsqFOjUEEQb72KxJZzFCbPgXnmNj0BGQogD/r3nS9EvrJXWSp6RbnhrgXO1bFa57qEou/QMpX5PPvePl8qixzgduIBMu/v0rOSPuO7s1qlx8diuoZtm0dqKRjTS22CBKQN+3h2RWdJq96yy+QBfaQlYhs5w+cZSi4Rmb9RV7XYiFbMQXquegKmp375sRBVEr/TOpmd8NOrm2f7PlQSH35GS5TcJZcgL88NK1M/w6604f1qWIyCKu3kmFQPS4GzTaMZfpFVGHH9Wec1qo47ZXIhKMUvauuLcV5zM65g94JlstzOyciTiox7ZgQIDAQAB";
	public $alipay_public_key   = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAm/j1QKrdEWyfAGyrmS6jBYDop1KfHltNum+v8yCGAYvGNeBd8iEg9WV5MG5X5Spxr3EZMFA5qF8hLCpOMfLYQWLhJOUvujMFuqyvT+ETSvR62/ZtoDlyqKpBO0+azp1ncUV5jXfd7WrPAM7nnuMEs3xvw6rshI+5e6OKjGTXUxbNmT3YGNe2zt7yG+8S7fDCqDky1ZvxWvQxzT2Z3ERovXE7IKw0HV/Jcl0q/GfTC1C2CDHQtosKNALzlehZcmtEISfGrmbq/V87+GxNU4hq7jGycgygadIEK7XWyoAlcu8BK9NoCl+kpcwcuKD/GuSDMEXmDPebNmEnHKFj5+4CEwIDAQAB";
		//公用变量
	public $serverUrl = 'http://publicexprod.d5336aqcn.alipay.net/chat/multimedia.do';//'http://publicexprod.d5336aqcn.alipay.net/chat/multimedia.do';//'http://i.com/works/photo-sdk/_data/1.jpg';//"http://i.com/works/photo-sdk/_data/publicexprod.php";//"http://publicexprod.d5336aqcn.alipay.net/chat/multimedia.do";
	public $appId = "2019050664390100";

	public $partner_private_key = 'MIIEowIBAAKCAQEAo1DVNK01WQpv2Lj3ckL+QwSU2B1xivsqFOjUEEQb72KxJZzFCbPgXnmNj0BGQogD/r3nS9EvrJXWSp6RbnhrgXO1bFa57qEou/QMpX5PPvePl8qixzgduIBMu/v0rOSPuO7s1qlx8diuoZtm0dqKRjTS22CBKQN+3h2RWdJq96yy+QBfaQlYhs5w+cZSi4Rmb9RV7XYiFbMQXquegKmp375sRBVEr/TOpmd8NOrm2f7PlQSH35GS5TcJZcgL88NK1M/w6604f1qWIyCKu3kmFQPS4GzTaMZfpFVGHH9Wec1qo47ZXIhKMUvauuLcV5zM65g94JlstzOyciTiox7ZgQIDAQABAoIBAGMYayYZa2Np18/y/AJS8CEOKJqx0vF30WL6m6J7EVBB3CdsZoqqoJvyuZiQcZFxIqtx42S3u2vHR03jxW74lpLn+M+SGCPZmfPh88J/T+pvIKwEAp1LSY1oHCd8jExUK3kVUJQ4ILGUvvHEb7EqH/jVmJQQjI6sVlDENCwCZ3F8Wo4qWbmn4iV59DtxVR0RjBUph3Bd5F1+0IAeVH9z/YJofw/7unFdcsWfd1BrRbVflQMvsSRIoQ1/+5zkYbqqHX1yjPnQxOijLQBinozuKlMLzs1r4GIjUZ9aflGgJ9GA5uO4M0sp2AHSvRAXkGg9N3/9HsIllKjpRcBnz8LZDjkCgYEA1M0iwg4GxHHLq4awrgqS4BWCRSfqp86J/n8cMUWV2cQQ4jabVuhw4gQYVP/RbFR9QNZ0SSkkmPHTh6fWTU1xNei1TtS+dL5ssB4/QHIhu7URHjHV3ZBTbUReO4d5kxyRN7PDHXEF3Qg8U2rS+aWZP9y7zfvAtWpYCfuLhtadOgsCgYEAxHgHvlD4R4rbpSLpqCuqe/iCXq5PJu1VqDZfihX0Z2Cwh5257easn1Ld7zagvvMeRgUGipL7PXSIzKhnaIUackwDFNua1rJxqrfZdLn4XKEILsvnBTSmrm1ujVshy9nqRVGTrmer97AoFsbvlACvO3JOWmWY+l1WwTYzE3K7/iMCgYBM4v1e/fBmA/Ohut2VVI6y1jKmSADZtp9XS5flGY5GCzhKc452vS8kCnS8KV4CdRh4V8PWNz5Y4G8cQYEFlyiDYNw5alaSGcdtbtBNua8Egix4K2tpTV9HSH9/pLhBdf3mEVY7Cf4jWXlqbltiBfoz/83/Y6nCInVCzhcgleRi9wKBgCIDbcPDHNi174TNYIpe1OsVgOyHXOiuWg//KdcsKd3j3Wv9IH1RXD1RCV8qo/Wq/Wi94f4HqDthe3WDCjQMJyH2iuoHguz8g7U8kwckUx0mO9ZuMpayINE93M/YISe7mFVb5Cdjh2AgPTCETGHhJHU0OuBnim59zlEw4vLRAD7lAoGBAMAoBojfS1s0S+qriWZeRE/6UsFWrqAyJ9N7dcgHGF40h2sh1Fki1hqw+5dY0lToBj2zPSIE2d5NjsYrCcI0yl942x2CT7EpbzbHCMONMlbn1KcBfkOVK7fgt85b9J3IZK209ib9zb9tO9n1ziiT6/RYuU9hwm34HPkUBtsoVFb3';

	public $format = "json";
	public $charset = "GBK";



	function __construct(){

	}

	public function load() {
		$alipayClient = new AlipayMobilePublicMultiMediaClient(
			$this -> serverUrl,
			$this -> appId,
			$this -> partner_private_key,
			$this -> format,
			$this -> charset
		);
		$response = null;
		$outputStream = null;
		$request = $alipayClient -> getContents() ;

		//200
		//echo( '状态码：'. $request -> getCode() .', ');
		//echo '<hr /><br /><br /><br />';

		$fileType = $request -> getType();
		//echo( '类型：'. $fileType .', ');
		if( $fileType == 'text/plain'){
			//出错，返回 json
			echo $request -> getBody();

		}else{

			$type = $request -> getFileSuffix( $fileType );

			//echo $this -> getParams();
			//exit();

			//返回 文件流
			header("Content-type: ". $fileType ); //类型


			header("Accept-Ranges: bytes");//告诉客户端浏览器返回的文件大小是按照字节进行计算的
			header("Accept-Length: ". $request -> getContentLength() );//文件大小
			header("Content-Length: ". $request -> getContentLength() );//文件大小
			header('Content-Disposition: attachment; filename="'. time() .'.'. $type .'"'); //文件名
			echo $request -> getBody() ;
			exit ( ) ;
		}

		//echo( '内容： , '. $request -> getContentLength()  );

		//echo '<hr /><br /><br /><br />';
		//echo  '参数：<pre>';

		//echo ($request -> getParams());

		//echo '</pre>' ;
	}
}





//  测试
$test1 = new TestImage();
$test1 -> load();
